﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DailyFx.UI
{
	public static class IoC
	{
		/// <summary>
		///		Gets an instance by type and key.
		/// </summary>
		public static Func<Type, string, object> DoGet = 
			(service, key) => 
			{ 
				throw new InvalidOperationException("IoC is not initialized."); 
			};

		/// <summary>
		///		Gets all instances of a particular type.
		/// </summary>
		public static Func<Type, IEnumerable<object>> DoGetAll = 
			service => 
			{ 
				throw new InvalidOperationException("IoC is not initialized."); 
			};

		/// <summary>
		///		Passes an existing instance to the IoC container to enable dependencies to be injected.
		/// </summary>
		public static Action<object> Satisfy = 
			instance => 
			{ 
				throw new InvalidOperationException("IoC is not initialized."); 
			};


		/// <summary>
        ///		Gets an instance from the container.
        /// </summary>
        public static T Get<T> ( string key = null ) 
		{
            return (T) DoGet (typeof(T), key) ;
        }

        /// <summary>
        ///		Gets all instances of a particular type.
        /// </summary>
        public static IEnumerable<T> GetAll<T> ()
		{
            return DoGetAll(typeof(T)).Cast<T>();
        }

	}
}
